package com.qsmx.store.app.main.mem;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.view.View;

import com.qsmx.store.app.R;
import com.qsmx.store.app.R2;
import com.qsmx.store.app.fustion.FustionTag;
import com.qsmx.store.app.main.mem.entity.MemManagerEntity;
import com.qsmx.store.core.delegates.AtmosDelegate;

import butterknife.BindView;
import butterknife.OnClick;

public class MemCardManagerInfoSetDelegate extends AtmosDelegate {

    private MemManagerEntity mMemManagerData;

    @BindView(R2.id.tv_base_info)
    AppCompatTextView tvBaseInfo;
    @BindView(R2.id.tv_important_info)
    AppCompatTextView tvImportantInfo;
    @BindView(R2.id.tv_password_reset)
    AppCompatTextView tvPasswordReset;

    @OnClick(R2.id.tv_base_info)
    void onBaseInfo() {
        onSetTitleCheckBg(tvBaseInfo);
        getSupportDelegate().replaceChildFragment(MemCardManagerBaseInfoDelegate.create(mMemManagerData), false);
    }

    @OnClick(R2.id.tv_important_info)
    void onImportantInfo() {
        onSetTitleCheckBg(tvImportantInfo);
        getSupportDelegate().replaceChildFragment(new MemCardManagerImportantDelegate(), false);
    }

    @OnClick(R2.id.tv_password_reset)
    void onPasswordReset() {
        onSetTitleCheckBg(tvPasswordReset);
        getSupportDelegate().replaceChildFragment(new MemCardManagerPasswordDelegate(), false);
    }

    public static MemCardManagerInfoSetDelegate create(MemManagerEntity memManagerData) {

        final Bundle args = new Bundle();
        args.putSerializable(FustionTag.MEM_CARD_INFO, memManagerData);

        final MemCardManagerInfoSetDelegate delegate = new MemCardManagerInfoSetDelegate();
        delegate.setArguments(args);
        return delegate;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Bundle args = getArguments();
        if (args != null) {
            mMemManagerData = (MemManagerEntity) args.getSerializable(FustionTag.MEM_CARD_INFO);
        }
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_mem_card_manager_info_set;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
        onSetTitleCheckBg(tvBaseInfo);
        getSupportDelegate().loadRootFragment(R.id.delegate_container, MemCardManagerBaseInfoDelegate.create(mMemManagerData));
    }

    public void onSetTitleCheckBg(AppCompatTextView tv) {
        tvBaseInfo.setBackgroundDrawable(getResources().getDrawable(R.drawable.round_corner_gary_title));
        tvImportantInfo.setBackgroundDrawable(getResources().getDrawable(R.drawable.round_corner_gary_title));
        tvPasswordReset.setBackgroundDrawable(getResources().getDrawable(R.drawable.round_corner_gary_title));

        tvBaseInfo.setTextColor(getResources().getColor(R.color.theme_black));
        tvImportantInfo.setTextColor(getResources().getColor(R.color.theme_black));
        tvPasswordReset.setTextColor(getResources().getColor(R.color.theme_black));

        tv.setBackgroundDrawable(getResources().getDrawable(R.drawable.round_corner_title_green_bg));
        tv.setTextColor(getResources().getColor(R.color.theme_white));
    }
}
